package freespiritsocial.io.user.weight

import android.content.Context
import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.bottomsheet.BottomSheetBehavior
import freespiritsocial.io.user.R
import freespiritsocial.io.user.data.model.BtnItems
import freespiritsocial.io.user.ext.init
import freespiritsocial.io.user.ui.adapter.BottomBtnAdapter
import me.hgj.jetpackmvvm.base.fragment.BaseBottomSheetDialogFragment

/**
 * 列表底部弹窗
 */
class BottomSheetListDialog(
    val mContext: Context,
    val list: ArrayList<BtnItems>,
    val callbacks: (Int) -> Unit
): BaseBottomSheetDialogFragment() {

    private val adapter by lazy(LazyThreadSafetyMode.NONE) {
        BottomBtnAdapter(list).apply {
            setOnItemClickListener { _,_,position ->
                callbacks.invoke(position)
                dismiss()
            }
        }
    }

    override fun onCreateView(inflater: LayoutInflater,container: ViewGroup?,savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.dialog_list_btn,container,false)

    }

    override fun onViewCreated(view: View,savedInstanceState: Bundle?) {
        super.onViewCreated(view,savedInstanceState)
        init(view)
    }

    private fun init(view: View) = with(view) {
        findViewById<RecyclerView>(R.id.recycler_view)?.init(adapter)
    }
}